﻿@using KRM.Core
@using KRM.Core.Library
@model IEnumerable<FrontPageCategory>
@{
    ViewBag.Title = "Frontpage Banner Management";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="~/js/jquery.jeditable.min.js"></script>
<script src="~/js/intranet.js"></script>
<script>
    $(document).ready(function () {
        FrontPageManagementV2.init();
    });
</script>
<div class="container-fluid">
    <div class="box">
        <div class="row-fluid">
            <p></p>
            <p>Select Website:</p>
            <form method="GET" action="/intranet/FrontPageManagementV2">
                <div class="span3">
                    @Html.DropDownList("StoreID",null,new {@id="WebsiteSelect",@class="input-block-level WebsiteSelect"})
                </div>
                <div class="span2">
                    <button id="GoButton" type="submit" class="btn btn-primary" >Go</button></div>
            </form>
        </div>
        <div class="row-fluid">
            <div class="span10">
                <div id="NewFrontPageItemForm"style="position: absolute; left: -999px; top: -999px;">
                    <span>Product Option: </span><a id="newProductOption" value="0"></a>(<a href="#SelectOption" id="SelectNewProductOption">Select a product option</a>)<br />
                    <div id="EditNewProduct" class="frontPageCategory">
                        <div class="product">
                            <a>
                                <img src="/img/intranet/product.jpg" alt="" class="EditNewProductImage" /></a>
                            <h3>New Product Title</h3>
                            <p class="prod-description">New product description</p>
                            <p class="prod-price">NOW £00.00</p>
                            <p class="prod-delivery">Delivery 2-5 Working Days*</p>
                        </div>
                    </div>
                    <input id="closeAddProduct2CatForm" type="button" value="Close" class="btn btn-danger" />
                    <input id="addProductToCategory" type="button" value="Add Product To " class="btn btn-primary" />
                </div>
                <div id="ProductOptionSearchDiv"style="position: absolute; left: -999px; top: -999px;">
                    <div id="ProductOptionSearchUserControl1" >
                        <div>
                            @Html.DropDownList("ListStoreDropDown")
                        </div>
                        <div id="ProductControl">
                            <Label>Filter</Label> 
                            <input id="txtProductSearchString" type="text" style="width: 320px" />
                            <input id="btnSearchProduct" type="button" value="Search Product"/>
                            <div id="ProductList">
                            </div> 
                            <div id="ProductOptionList">
                            </div>            
                            <div class="Push"></div>        
                        </div>
                        <div id="SelectedOptionInfo"style="padding-left: 450px;margin-top: 10px;">
                            <input id="hdProductId" type="hidden" />
                            <input id="hdProductOptionId" type="hidden" />
                            <b>Selected Product :</b>  <a href="#ProductExtraInformation" id="ProductExtraInformation"><span id="SelectedProduct">~</span></a><br />
                            <b>Selected Option :</b>  <span id="SelectedOption">~</span>
                        </div>
                    </div>

                    <div style="text-align: right;">
                        <input id="CloseForProductOptionSearchButton" type="button" value="Close" class="btn btn-danger" />
                        <input id="OkForProductOptionSearchButton" type="button" value="Ok" class="btn btn-primary" />
                    </div>
                </div>
                <div class="categoryBarControl short">
                    <a class="RearrangeCategoriesButton" onclick="FrontPageManagementV2.ReArrangeCategories()">
                        <img src="/img/intranet/page_component.gif">
                        Re-arrange Categories
                    </a>
                </div>
                <div id="frontPageContent" class="front-page-content">
                    @foreach (var item in Model.OrderBy(p=>p.Position))
                    {
                        <div id='@item.ID' class='frontPageCategory'>
                            <h2>@item.Name</h2>
                            <p class='cat-info'>@Html.Raw(item.Description)</p>
                            @foreach (FrontPageProductOption optionItem in item.FrontPageProductOptions.OrderBy(p => p.Position))
                            {
                                if (optionItem.ProductOption != null && optionItem.ProductOption.tblProduct != null)
                                {
                                    tblProduct thisProduct = optionItem.ProductOption.tblProduct;
                                    <div class='product' id='option-@optionItem.ID'><a><img src='http://www.gardenbuildingsdirect.co.uk/images/products/@((thisProduct.ProductImage.Length == 0) ? "" : thisProduct.ProductImage)' alt=''/></a>
                                        <h3 value='@optionItem.ProductOption.ProductOptionID'> @optionItem.Title"</h3>
                                        <p class='prod-description'>@optionItem.Description</p>
                                        <p class='prod-price'>NOW £@optionItem.ProductOption.ProductOptionBasePrice.ToString("N2")</p>
                                        <p class='prod-delivery'>Delivery @optionItem.ProductOption.OptionDays.ToString() Working Days</p>
                                        <a  onclick='FrontPageManagementV2.DeleteOption(@optionItem.ID)' >
                                            <img src='/img/intranet/clickbut.gif' alt='' /></a></div>
                                }
                            }
                            <div class='categoryBarControl' data-id='@item.ID'> 
                                <a class='RearrangeOptionButton' onclick='FrontPageManagementV2.ReArrangeOptions(@item.ID)'><img src='/img/intranet/page_component.gif'> Re-arrange</a>
                                <a class='NewOptionButton' onclick='FrontPageManagementV2.OpenFormAddNewProductToCategory(@item.ID)'><img src='/img/intranet/page_new.gif'> Add option</a>
                                <a class='DeleteCatButton' onclick='FrontPageManagementV2.DeleteCategory(@item.ID)'><img src='/img/intranet/folder_delete.gif'> Delete category</a>
                            </div>
                            <div class='clear-bottom'></div>
                        </div>
                    }
                </div>
                <div id="NewFrontPageCategoryForm">
                    <span>Category Title: </span>
                    <input id="categoryTitleText" type="text" /><br />
                    <span>Information: </span>
                    <input id="categoryInfoText" type="text" /><br />
                    <div style="text-align: right; clear: both;">
                        <input id="addCategoryButton" type="button" value="Add Category" class="btn btn-primary" />
                    </div>
                </div>
                <div id="ajax-error"></div>
            </div>
        </div>
    </div>
</div>
